/**
*
*   CSS document
*   Created by 紫相 on 2015/1/1.
*
**/
window.onload = function(){
  var oMain = document.getElementById("main");
  var oLoading = document.getElementById("loading");
  var aDiv = oLoading.getElementsByTagName("div");
  var oSpan = oLoading.getElementsByTagName("span")[0];

  var arr = [
    "about2.jpg",
    "about3.jpg",
    "about4.jpg",
    "bg1.jpg",
    "bg2.jpg",
    "bg3.jpg",
    "bg4.jpg",
    "bg5.jpg",
    "greenLine.png",
    "team.png",
    "worksimg1.jpg",
    "worksimg2.jpg",
    "worksimg3.jpg",
    "worksimg4.jpg",
  ];
  var spanlangNum = 0;
  for(var i=0;i<arr.length;i++){
    var objImg = new Image();
    objImg.src = "img/" + arr[i];
    objImg.onload = function(){
      spanlangNum++;
      oSpan.style.width = spanlangNum/arr.length*100 + "%";
    }
  }

  oSpan.addEventListener("transitionend", spanChang, false);
  oSpan.addEventListener("webkitTransitionEnd",spanChang, false);
  function spanChang(){
    if(oSpan.style.width == "100%"){
      oSpan.style.display = "none";
      aDiv[0].style.height = 0;
      aDiv[1].style.height = 0;
    }
  }

  aDiv[0].addEventListener("transitionend", divChange, false);
  aDiv[0].addEventListener("webkitTransitionEnd", divChange, false);
  function divChange(){
    oMain.removeChild(oLoading);
  }
}